﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace OneLine
{
    class Level : GameComponent
    {
        private Map map;

        public List<Texture2D> tileTextures = new List<Texture2D>();

        public VertexPositionColorTexture[] Verts { get; protected set; }


        public Level(Game game, Map map)
            : base(game)
        {
            this.map = map;
        }

        public int Width
        {
            get { return map.Width; }
        }
        public int Height
        {
            get { return map.Height; }
        }

        public override void Initialize()
        {
            List<VertexPositionColorTexture> v = new List<VertexPositionColorTexture>();

            for (int x = 0; x < Width; x++)
            {
                for (int y = 0; y < Height; y++)
                {
                    int textureIndex = map.GetIndex(x, y);
                    //if (textureIndex == -1)
                    //    continue;

                    Color color = Color.DarkGreen;
                    if (textureIndex == 1)
                        color = Color.Green;
                    
                    v.Add(new VertexPositionColorTexture(new Vector3(0.0f + x, 0, 0.0f + y), color, new Vector2(0, 0)));
                    v.Add(new VertexPositionColorTexture(new Vector3(1.0f + x, 0, 1.0f + y), color, new Vector2(0, 0)));
                    v.Add(new VertexPositionColorTexture(new Vector3(0.0f + x, 0, 1.0f + y), color, new Vector2(0, 0)));

                    v.Add(new VertexPositionColorTexture(new Vector3(0.0f + x, 0, 0.0f + y), color, new Vector2(0, 0)));
                    v.Add(new VertexPositionColorTexture(new Vector3(1.0f + x, 0, 0.0f + y), color, new Vector2(0, 0))); 
                    v.Add(new VertexPositionColorTexture(new Vector3(1.0f + x, 0, 1.0f + y), color, new Vector2(0, 0)));
                }
            }

            Verts = v.ToArray();

            // Set vertex data in VertexBuffer
            //vertexBuffer = new VertexBuffer(Game.GraphicsDevice, typeof(VertexPositionColorTexture),
            //    Verts.Length, BufferUsage.None);
            //vertexBuffer.SetData(Verts);

            base.Initialize();
        }

    }
}
